<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH . 'controllers/admin.php';

/**
 * Контроллер просмотра и изменения основных настроек
 *
 * @package CoreFramework
 * @version 1.0
 * @author Gennadiy Kozlenko
 */
class Admin_General_Settings extends Admin {
   
   /**
    * Конструктор класса
    *
    * @access public
    * @return Admin_General_Settings
    */
   function Admin_General_Settings() {
      parent::Admin();
      $this->set_menu(2, 1);
   } // end Admin_General_Settings
   
   /**
    * Метод по умолчанию
    *
    * @access public
    */
   function index() {
      $data = array();
      // Стандартные поля
      $site_name = $this->variables->get('site_name');
      $site_email = $this->variables->get('site_email');
      $site_slogan = $this->variables->get('site_slogan');
      // Валидируем и, если нужно, изменяем
      if (false !== $this->input->post('edit')) {
         $this->load->library('validation');
         $rules = array(
            'site_name'   => 'trim|required',
            'site_slogan' => 'trim',
            'site_email'  => 'trim|required|valid_email'
         );
         $this->validation->set_rules($rules);
         $result = $this->validation->run();
         // Получаем из поста поля
         $site_name = $this->validation->site_name;
         if (isset($this->validation->site_slogan)) {
             $site_slogan = $this->validation->site_slogan;
         } else {
             $site_slogan = '';
         }
         $site_email = $this->validation->site_email;
         if ($result) {
            // Если проверки пройдены успешно, изменяем
            $this->variables->set('site_name', $site_name);
            $this->variables->set('site_slogan', $site_slogan);
            $this->variables->set('site_email', $site_email);
            $this->set_message($this->lang->line('edit_settings_succ'), 'info', true);
            $this->redirect($this->get_controller());
         }
      }
      // Забиваем в дату поля
      $data['site_name'] = htmlspecialchars($site_name);
      $data['site_slogan'] = htmlspecialchars($site_slogan);
      $data['site_email'] = htmlspecialchars($site_email);
      // Выводим
      $this->set_content($this->parser->parse('admin/general_settings.html', $data, true));
      $this->display();
   } // end index
   
}
